
local scene   = require "guac.scene"
local screen  = require "guac.screen"

local pairs, print
    = pairs, print

local scene_node
    = scene.node
local screen_drawImage
    = screen.drawImage

setfenv(1, scene)

local sprite_proto = {x = 0, y = 0, z = 0}

function scene.sprite(def)
  def = def or {}
  for k,v in pairs(sprite_proto) do
    if (def[k] == nil) then
      def[k] = v
    end
  end
  return scene_node(def)
end

function sprite_proto:render()
  if not self.hidden then
    local image = self.image
    if not image then
      return
    end
    screen_drawImage(image, self.x, self.y, self.xflip, self.yflip)
  end
end

function sprite_proto:hide()
  self.hidden = true
end

function sprite_proto:show()
  self.hidden = false
end

function sprite_proto:position(newx, newy, newz)
  if newx then
    self.x, self.y, self.z = newx, newy, newz
  else
    return self.x, self.y, self.z
  end
end

return scene.sprite
